from rest_framework import serializers
from apps.orders.models import OrderInfo
from apps.orders.models import OrderGoods
from apps.goods.models import SKU


class SKUSerializer(serializers.ModelSerializer):
    """获取商品名称和图片"""
    class Meta:
        model = SKU
        fields = ['name', 'default_image']


class OrderGoodsSerializer(serializers.ModelSerializer):
    """订单商品详细信息"""
    # 关联商品名称和图片信息
    sku = SKUSerializer()

    class Meta:
        model = OrderGoods
        fields = ['count', 'price', 'sku']


class OrderInfoSerializer(serializers.ModelSerializer):
    """订单信息详情"""
    # 关联订单商品信息
    skus = OrderGoodsSerializer(many=True, read_only=True)

    class Meta:
        model = OrderInfo
        fields = '__all__'
